import bb.cascades 1.3
import bb.data 1.0
import "lib"

TabbedPane {
    id: tabRoot
    showTabsOnActionBar: false
    property NavigationPane navRoot: headline.navHandle
    //gjq usr 
    onActiveTabChanged: {
        console.log("TabbedPane : onActiveTabChanged : activeTab.title = " + activeTab.title);
        navRoot = activeTab.navHandle;
    }
    
    Menu.definition: [
        MenuDefinition {
            actions: [
                ActionItem {
                    title: qsTr("About")+ Retranslate.onLocaleOrLanguageChanged
                    imageSource: "asset:///images/ic_About.png"
                    onTriggered: {
                        var docCom = Qt.createComponent("asset:///About.qml")
                        var docView = docCom.createObject(navRoot);
                        navRoot.push(docView);
                    }
                },
                
                ActionItem {
                    title: qsTr("Setting")+ Retranslate.onLocaleOrLanguageChanged
                    onTriggered: {
                        var docCom = Qt.createComponent("asset:///Setting.qml")
                        var docView = docCom.createObject(navRoot);
                        navRoot.push(docView);
                    }
                },
                
                ActionItem {
                    title: qsTr("Feedback")+ Retranslate.onLocaleOrLanguageChanged
                    imageSource: "asset:///images/ic_Feedback.png"
                    onTriggered: {
                        var body = qsTr("Device name:%1;System version:%2.").arg(com.hardwareInfo.modelName).arg(com.platForm.osVersion)+ Retranslate.onLocaleOrLanguageChanged
                        _Setting.inVoke("sys.pim.uib.email.hybridcomposer", "bb.action.SENDEMAIL", "text/html", "mailto:251998542@qq.com?subject=凤凰新闻用户反馈&body="+body, "")
                    }
                },
                
                ActionItem {
                    title: qsTr("Rate App")+ Retranslate.onLocaleOrLanguageChanged
                    imageSource: "asset:///images/rate.png"
                    onTriggered: {
                        Qt.openUrlExternally("appworld://content/55063888")
                    }
                }
            ]
        }
    ]
    
    Tab {
        id: headline
        property alias navHandle: _Headline
        title: qsTr("Headline")
        List {
            id: _Headline
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=SYLB10,SYDT10&page=1&random=0"
        }
    }
    
    Tab {
        id: zhuanti
        property alias navHandle: _Zhuanti
        title:qsTr("Zhuanti")
        List {
            id: _Zhuanti
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=ZTPD,FOCUSZTPD&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: keji
        property alias navHandle: _Keji
        title:qsTr("Tech")
        List {
            id: _Keji
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=KJ123,FOCUSKJ123&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: qiche
        property alias navHandle: _Qiche
        title:qsTr("Automobile")
        List {
            id: _Qiche
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=QC45,FOCUSQC45&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: tiyu
        property alias navHandle: _Tiyu
        title:qsTr("Sports")
        List {
            id: _Tiyu
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=TY43,FOCUSTY43,TYLIVE&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: shendu
        property alias navHandle: _Shendu
        title:qsTr("Deep reading")
        List {
            id: _Shendu
            baseUrl: "http://api.iclient.ifeng.com/clientShortNews?type=depth&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: junshi
        property alias navHandle: _Junshi
        title:qsTr("Military")
        List {
            id: _Junshi
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=JS83,FOCUSJS83&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050&action=down"
        }
    }
    
    Tab {
        id: caijing
        property alias navHandle: _Caijing
        title:qsTr("Finance")
        List {
            id: _Caijing
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=CJ33,FOCUSCJ33,HNCJ33&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: jiankang
        property alias navHandle: _Jiankang
        title:qsTr("Health")
        List {
            id: _Jiankang
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=JK36,FOCUSJK36&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050&action=default"
        }
    }
    
    Tab {
        id: shishang
        property alias navHandle: _Shishang
        title:qsTr("Fashion")
        List {
            id: _Shishang
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=SS78,FOCUSSS78&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    Tab {
        id: guoji
        property alias navHandle: _Guoji
        title:qsTr("International")
        List {
            id: _Guoji
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=GJPD&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050&action=default"
        }
    }
    
    Tab {
        id: pinglun
        property alias navHandle: _Pinglun
        title:qsTr("Comment")
        List {
            id: _Pinglun
            baseUrl: "http://api.iclient.ifeng.com/ClientNews?id=PL40,FOCUSPL40&page=1&gv=5.2.0&av=5.2.0&uid=23443bf0100c081e&deviceid=23443bf0100c081e&proid=ifengnews&os=android_19&df=androidphone&vt=5&screen=480x854&publishid=5050"
        }
    }
    
    onCreationCompleted: {
        app.invokeChanged.connect(invoke);
        channel.load();
    }
    
    function invoke(url){
        console.log("URL->"+url);
        invokeData.source = url;
        invokeData.load();
    }
    
    function addTab(item){
        var docView = tabTemp.createObject(tabRoot);
        docView.title = item.title
        docView.baseUrl = item.url
        tabRoot.add(docView)
    }
    
    attachedObjects: [
        Common{
            id: com
        },
        
        ComponentDefinition {
            id: tabTemp
            Tab {
                property alias baseUrl: _tab.baseUrl
                property alias navHandle: _tab
                imageSource: "asset:///images/Toutiao.png"
                List {
                    id: _tab
                    
                    onNavRootChanged: {
                        navRoot = root;
                        console.log("navRoot"+navRoot);
                    }
                }
            }
        },
        
        DataSource {
            id: invokeData
            onDataLoaded: {
                var docCom = Qt.createComponent("asset:///ViewSlider.qml")
                var docView = docCom.createObject(navRoot);
                docView.url = data.meta.id;
                navRoot.push(docView);
            }
            
            onError: {
                console.log("Error")
            }
        },
        
        DataSource{
            id: channel
            source: "http://m.scykw.cn/api/ifengnews/channel.aspx"
            onDataLoaded: {
                return;
                
                for(var i=0;i<data.length;i++){
                    var item  = data[i];
                    var docView = tabTemp.createObject(tabRoot);
                    docView.imageSource = item.icon;
                    docView.title = item.title
                    docView.baseUrl = item.url
                    tabRoot.add(docView);
                }
            }   
            
            onError: {
                console.log("Load Channel Error."+errorMessage+";errorType:"+errorType)
            } 
        }
    ]
}
